package com.example.administrator.dc.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.dc.Bean.UserPhoto;
import com.example.administrator.dc.R;
import com.example.administrator.dc.Service.UserphotoListener;
import com.example.administrator.dc.adapter.UserPhotoListAdapter;
import com.example.administrator.dc.model.UsersModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;

;import static android.R.id.list;

/**
 * A simple {@link Fragment} subclass.
 */
public class UserphotoFragment extends Fragment implements UserphotoListener{
      private RecyclerView recyclerView;
    int lastVisibleItemPosition;
    private View view;
    List<UserPhoto> list;


    public UserphotoFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
       view= inflater.inflate(R.layout.fragment_userphoto, container, false);
        initViews();
         getData();
       /* Intent intent=getActivity().getIntent();
        intent.getStringExtra("images");*/
     /*   recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                System.out.println("==>>"+"newState="+newState);

                if (newState==RecyclerView.SCROLL_STATE_IDLE && lastVisibleItemPosition ==list.size()-1){
                    cur_page++;
                    System.out.println("==>>"+"cur_page="+cur_page);
                    ArticleModel articleModel=new ArticleModel();
                    articleModel.getResultList("article",cur_page,sessionId,Fragment1_Article.this);
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                lastVisibleItemPosition=layoutManager.findLastVisibleItemPosition();
                System.out.println("==>>"+"lastVisibleItemPosition="+lastVisibleItemPosition);

            }
        });*/
        return view;
    }
    private void initViews(){
        recyclerView=(RecyclerView)view.findViewById(R.id.userphoto_recycleview_id);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));


    }
    private void getData(){
        //获取网上的数据/
      /*  UsersModel shopModel=new  UsersModel();
        Call<List<UserPhoto>> call=shopModel.userphotolist();

        call.enqueue(new Callback<List<UserPhoto>>() {
            @Override
            public void onResponse(Call<List<UserPhoto>> call, retrofit2.Response<List<UserPhoto>> response)
            {
                List<UserPhoto> res=response.body();

                recyclerView.setAdapter(new UserPhotoListAdapter(getActivity(),res));

            }
            @Override
            public void onFailure(Call<List<UserPhoto>> call, Throwable t) {

            }
        });*/


    }




    public void onResume() {
        getData();
        super.onResume();

    }

    @Override
    public void onResponse(List<UserPhoto> beanList) {

    }

    @Override
    public void onFail(String msg) {

    }
}
